package Lee_code;

import java.util.HashSet;
import java.util.List;

/**
 * @author blh
 * @date 2024年07月02日 18:09
 */
public class Lee_139_72 {
    public boolean wordBreak(String s, List<String> wordDict) {
        int len = s.length();
        HashSet<String> hashSet = new HashSet<>(wordDict);
        boolean[] dp = new boolean[len+1];

        for (int i = 1; i <= len; i++) {
            for (int j = 0; j <= i; j++) {
                if (dp[j] && hashSet.contains(s.substring(j, i))) {
                    dp[i] = true;
                    break;
                }
            }
        }
        return dp[len];
    }
}
